﻿using System;
using Aptea.OpenXmlOffice;
using eCRAM.Model;
using DocumentFormat.OpenXml.Spreadsheet;

namespace eCRAM.Bll
{
    public class ExcelSheetGenerator
    {
        public ExcelManager ExcelManager { get; set; }
        public uint IdxRow { get; set; }
        public Worksheet WorkSheet { get; set; }
        public Cram Cram { get; set; }
        public int NbProject { get; set; }
        public Func<CramLine, bool> ProjectPredicate { get; set; }
        public Func<CramLine, bool> HolidayPredicate { get; set; }


        /// <summary>
        /// Définit les largeurs des colonnes du document
        /// </summary>
        public void SetColumnWidth()
        {
            // 1ere colonne => colonne vide faisant office de marge
            ExcelManager.AddColumnData(WorkSheet, 1, 1, 3);
            
            // 2eme colonne 
            ExcelManager.AddColumnData(WorkSheet, 2, 2, 22);

            // Colonnes contenant les détails des imputations
            ExcelManager.AddColumnData(WorkSheet, 3, 33, 3);

            // Colonne total
            ExcelManager.AddColumnData(WorkSheet, 34, 34, 4);

            // Colonne visa
            ExcelManager.AddColumnData(WorkSheet, 35, 35, 10);
        }

        public uint AddBody()
        {
            var excelSheetBodyGenerator = new ExcelSheetBodyGenerator
            {
                ExcelManager = ExcelManager,
                WorkSheet = WorkSheet,
                Cram = Cram,
                IdxRow = IdxRow,
                ProjectPredicate = ProjectPredicate,
                HolidayPredicate = HolidayPredicate,
                NbProject = NbProject
            };

            IdxRow = excelSheetBodyGenerator.Generate();
            IdxRow++;
            return IdxRow;
        }

        public uint AddHeader()
        {
            var excelSheetHeaderGenerator = new ExcelSheetHeaderGenerator
            {
                ExcelManager = ExcelManager,
                WorkSheet = WorkSheet,
                IdxRow = IdxRow,
                Cram = Cram
            };

            IdxRow = excelSheetHeaderGenerator.Generate();

            return IdxRow;
        }

        public uint AddFooter()
        {
            var excelSheetFooterGenerator = new ExcelSheetFooterGenerator
            {
                ExcelManager = ExcelManager,
                WorkSheet = WorkSheet,
                IdxRow = IdxRow,
                Cram = Cram
            };

            IdxRow = excelSheetFooterGenerator.Generate();

            return IdxRow;
        }
    }
}
